<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>三角形的最大周长</title>
</head>
<body>
  <script>
    function fn(n) {
      n.sort((a, b) => a - b);
      for (let i = 2; i <= n.length - 1; ++i) {
        if (n[i - 2] + n[i - 1] > n[i]) {
          return n[i - 2] + n[i - 1] + n[i]
        }
      }
      return 0
    }
    console.log(fn([2, 1, 2]))
  </script>
</body>
</html>